package m1;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.Scanner;

public class Producer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
//        新建生产者实例
        DefaultMQProducer p = new DefaultMQProducer("producer-group-1");
//        新建注册中心
        p.setNamesrvAddr("192.168.64.141:9876");
//        启动生产者
        p.start();
//        发送消息
        while (true) {
            System.out.println("enter:");
            String s= new Scanner(System.in).nextLine();
//            topic:主题，一级分类
//            tag：标签 ，二级分类
            Message m=new Message("Topic1","TagA",s.getBytes());
//          设置延迟时间
            m.setDelayTimeLevel(3);

            SendResult r=p.send(m);
            System.out.println(r);
        }
    }
}
